{{define "login/index.html"}}
{{template "header" .}}
{{template "sha1" .}}



<title>登录</title>
<style>
	html,
	body {
		width: 100%;
		height: 100%;
		margin: 0;
		padding: 0;
	}

	.content {
		width: 350px;
		height: 220px;
		/*background: orange;*/
		margin: 0 auto;
		/*水平居中*/
		position: relative;
		top: 50%;
		/*偏移*/
		transform: translateY(-50%);
	}
</style>
</head>

<body>
	<div class="content">
		<br />
		<div style="text-align: center; margin-bottom: 10px;">
			<h2>登录系统</h2>
		</div>
		<form class="layui-form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">账号</label>
				<div class="layui-input-inline">
					<input type="text" name="username" required lay-verify="required" placeholder="请输入账号" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">密码</label>
				<div class="layui-input-inline">
					<input type="password" name="password" id="password" required lay-verify="required" placeholder="请输入密码"
						autocomplete="off" class="layui-input">
				</div>
				<div class="layui-form-mid layui-word-aux">辅助</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-primary" lay-submit lay-filter="formLogin">登陆系统</button>
					<button type="reset" class="layui-btn layui-btn-primary">重&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;置</button>
				</div>
			</div>
		</form>
	</div>

	<script>
		var form = layui.form;
		//监听提交
		form.on('submit(formLogin)', function (data) {
			try {
				data = data.field;
				if (data.username == "") {
					layer.msg("账号不能为空");
					return false;
				}
				var hash = sha1.create();
				hash.update(data.password);
				var pwd = hash.hex();
				$('#password').val(pwd);
				data.password = pwd;
				console.log(JSON.stringify(data));
				$.ajax({
					type: "POST", url: "/v1/login/index",
					data: data,
					success: function (data) {
						if (data == null || data.msg == null || data.code == null) {
							layer.msg("服务器应答错误")
							return
						}
						if(data.code != 200){
							layer.msg(data.msg);
							return false
						}
						window.location.href = "/";
					},
					error: function (msg) {
						layer.msg("网络错误")
					}
				})
			} catch (err) {
				layer.msg("操作错误:" + err);
				return false;
			}
			return false;
		});

	</script>
</body>

</html>
{{end}}